<!--
 * @Author: HeAo
 * @Date: 2021-12-22 16:33:02
 * @LastEditTime: 2022-01-06 21:16:00
 * @LastEditors: 杨雨翰
 * @Description: 
 * @FilePath: \am-ui\src\pages\am\monitor\Video.vue
 * 别乱动！
-->
<!--<template>
  <div class="video">视频监控</div>
</template>-->
<template>
  <div class="history">
    <div class="content">
      <div class="left">
        <el-input
          class="search"
          placeholder="请输入设备关键字"
          v-model="filterText"
          style="width: 97%; margin-top: 10px; margin-bottom: 10px"
        >
        </el-input>
        <!-- <img src="..\..\..\icons\svg\搜索.png" /> -->
        <el-tree
          class="filter-tree"
          :data="edTree"
          :props="props"
          @node-click="handleNodeClick"
          :filter-node-method="filterNode"
          ref="tree"
        >
        </el-tree>
      </div>
      <div class="right">
        <div class="action">请选择设备</div>
        <el-dialog @close="dialogCloseHandler" :visible.sync="visible">
          <div v-if="device.video !== null" class="action">
            <video
              class="video"
              :src="device.video"
              autoplay
              controls
              loop
              style="display: block; width: 90%; margin: 0 auto"
            ></video>
          </div>
          <div v-else class="action">该设备没有视频</div>
          <!-- {{ device.video }} -->
        </el-dialog>
      </div>
    </div>
  </div>
</template>
<script>
import { get } from "@/utils/request.js";
export default {
  data() {
    return {
      edTree: [],
      props: {
        label: "name",
        value: "id",
      },
      params: {
        page: 1,
        pageSize: 50,
      },
      device: {},
      filterText: "",
      visible: false,
    };
  },
  watch: {
    //监测输入框内容
    filterText(val) {
      this.$refs.tree.filter(val);
    },
  },
  methods: {
    //对树节点进行筛选时执行的方法，返回 true 表示这个节点可以显示，返回 false 则表示这个节点会被隐藏。
    filterNode(value, edTree) {
      // console.log(edTree.name.indexOf(value));
      //value是输入框输入的值
      if (!value) return true;

      //返回名称与输入值相同的edTree
      //indexOf(value)==-1不显示
      return edTree.name.indexOf(value) !== -1;
    },
    findDeviceVideo() {
      // console.log(this.params.device_id);
      get("/device/findDeviceDetail", { id: this.params.device_id }).then(
        (res) => {
          this.device = res.data;
        }
      );
    },
    //树形节点点击事件
    handleNodeClick(data) {
      // console.log(data);
      //点击工程不查询
      if (data.engineer_id) {
        this.params = {
          ...this.params,
          engineer_id: data.engineer_id,
          device_id: data.id,
        };
        // this.$set(this.params, "engineer_id", data.engineer_id);
        // this.$set(this.params, "device_id", data.id);
        // 调用请求数据的方法
        // console.log(this.params.device_id);
        this.findDeviceVideo();
        this.visible = true;
      }
    },
    //查询工程设备树
    findEngineerDeviceTree() {
      get("/engineer/findEngineerDeviceTree").then((res) => {
        let arr = res.data;
        arr.forEach((element, index) => {
          //遍历arr
          if (element.children.length == 0) {
            //将空的删掉
            delete arr[index];
          }
        });
        // console.log(arr);
        var r = arr.filter((item) => {
          //过滤掉空的
          return item !== null || item !== undefined || item !== "";
        });
        // console.log(r);
        this.edTree = r;
      });
    },
    // 模态框关闭回调
    dialogCloseHandler() {},
  },
  created() {
    this.findEngineerDeviceTree();
  },
};
</script>
<style scoped>
.content {
  display: flex;
}
.left {
  width: 30%;
  border-right: 1px solid #d9d9d9;
}
.right {
  margin-left: 20px;
  width: 70%;
}
.action {
  height: 500px;
  line-height: 500px;
  text-align: center;
  font-size: 60px;
  font-family: 微软雅黑;
  font-weight: 900;
  color: #999999;
}
::v-deep .el-icon-caret-right:before {
  content: "\e723";
  font-size: 16px;
}

::v-deep .expanded:before {
  content: "\e722";
  font-size: 16px;
}
.video {
  width: 600px;
  height: 500px;
}
</style>